<?php
/*$link = mysql_connect("localhost","root","");
mysql_select_db('signinventory',$link);
*/
$link = mysql_connect("localhost","webapp-devel","nd8h3EH8fh3");
mysql_select_db('test',$link);

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

/*// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}*/

// Select all the rows in the markers table
$query = "SELECT * FROM Sign_Posts WHERE `sp_catalog_item_yesno` = '2'";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['sp_id']) . '" ';
  echo 'address="' . parseToXML('address') . '" ';
  echo 'lat="' . $row['sp_latitude'] . '" ';
  echo 'lng="' . $row['sp_longitude'] . '" ';
  echo 'type="' . 'bar' . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>
